<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增资产盘点')" />
    <th:block th:include="include :: datetimepicker-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-check-add">
            <input name="checkDepts" type="hidden" id="treeId"/>
            <h4 class="form-header h4">资产盘点信息</h4>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">盘点编号：</label>
                <div class="col-sm-8">
                    <input name="checkNo" readonly="readonly" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">盘点名称：</label>
                <div class="col-sm-8">
                    <input name="checkName" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">盘点时间：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <input name="checkTime" class="form-control" placeholder="yyyy-MM-dd" type="text" required>
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                    </div>
                </div>
            </div>
            <!--<div class="form-group">    -->
                <!--<label class="col-sm-3 control-label is-required">盘点状态：</label>-->
                <!--<div class="col-sm-8">-->
                    <!--<select name="checkStatus" disabled="disabled" class="form-control m-b" th:with="type=${@dict.getType('check_status')}" required>-->
                        <!--<option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>-->
                    <!--</select>-->
                <!--</div>-->
            <!--</div>-->
            <div class="form-group">    
                <label class="col-sm-3 control-label">资产类别：</label>
                <div class="col-sm-8" th:with="type=${@dict.getType('assets_type')}">
                    <label th:each="dict : ${type}" class="check-box">
                        <input name="checkAssetsType" type="checkbox" th:value="${dict.dictValue}" th:text="${dict.dictLabel}">
                    </label>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">资产状态：</label>
                <div class="col-sm-8" th:with="type=${@dict.getType('assets_status')}">
                    <label th:each="dict : ${type}" class="check-box">
                        <p th:if="${dict.dictValue != '4'}">
                            <input name="checkAssetsStatus" type="checkbox" th:value="${dict.dictValue}" th:text="${dict.dictLabel}">
                        </p>
                    </label>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">盘点部门：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <input name="checkDeptsName" id="treeName" class="form-control" type="text" readonly="readonly">
                        <span class="input-group-addon input-sm" onclick="selectDeptTree()">
                            <i class="fa fa-search"></i>
                        </span>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">盘点说明：</label>
                <div class="col-sm-8">
                    <textarea name="checkDesc" class="form-control"></textarea>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <script th:inline="javascript">
        $(document).ready(function(){
            var currtime = new Date().Format("yyyy-MM-dd");
            $("*[name='checkTime']").val(currtime);

            var checkNo = new Date().Format("yyyyMMddHHmmss");
            $("*[name='checkNo']").val('C'+checkNo);
        });

        var prefix = ctx + "assets/check"
        var checkFlagDatas = [[${@dict.getType('check_status')}]];
        var assetsTypeDatas = [[${@dict.getType('assets_type')}]];
        var assetsStatusDatas = [[${@dict.getType('assets_status')}]];
        $("#form-check-add").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/add", $('#form-check-add').serialize());
            }
        }

        $("input[name='checkTime']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });

        /* 新增-选择部门树 */
        function selectDeptTree() {
            var treeId = $("#treeId").val();
            var deptId = $.common.isEmpty(treeId) ? "0" : $("#treeId").val();
            var url = ctx + "system/dept/selectDeptTree/" + deptId;
            var options = {
                title: '选择部门',
                width: "380",
                url: url,
                callBack: doSubmit
            };
            $.modal.openOptions(options);
        }

        function doSubmit(index, layero){
            var tree = layero.find("iframe")[0].contentWindow.$._tree;
            var body = $.modal.getChildFrame(index);
            $("#treeId").val(body.find('#treeId').val());
            $("#treeName").val(body.find('#treeName').val());
            $.modal.close(index);
        }

        Date.prototype.Format = function (fmt) {
            var o = {
                "M+": this.getMonth() + 1, //月份
                "d+": this.getDate(), //日
                "H+": this.getHours(), //小时
                "m+": this.getMinutes(), //分
                "s+": this.getSeconds(), //秒
                "q+": Math.floor((this.getMonth() + 3) / 3), //季度
                "S": this.getMilliseconds() //毫秒
            };
            if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
            for (var k in o)
                if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
            return fmt;
        }
    </script>
</body>
</html>